<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Finds position of first occurrence of a needle within a haystack</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.iconv-strlen.html">« iconv_strlen</a></li>
      <li style="float: right;"><a href="function.iconv-strrpos.html">iconv_strrpos »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.iconv.html">iconv 函数</a></li>
    <li>Finds position of first occurrence of a needle within a haystack</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.iconv-strpos" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">iconv_strpos</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">iconv_strpos</span> &mdash; <span class="dc-title">Finds position of first occurrence of a needle within a haystack</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.iconv-strpos-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>iconv_strpos</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$haystack</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$needle</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$encoding</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type"><span class="type">int</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Finds position of first occurrence of a <code class="parameter">needle</code>
   within a <code class="parameter">haystack</code>.
  </p>
  <p class="para">
   In contrast to <span class="function"><a href="function.strpos.html" class="function">strpos()</a></span>, the return value of
   <span class="function"><strong>iconv_strpos()</strong></span> is the number of characters that
   appear before the needle, rather than the offset in bytes to the
   position where the needle has been found. The characters are counted
   on the basis of the specified character set <code class="parameter">encoding</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.iconv-strpos-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">haystack</code></dt>

     <dd>

      <p class="para">
       The entire string.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">needle</code></dt>

     <dd>

      <p class="para">
       The searched substring.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">offset</code></dt>

     <dd>

      <p class="para">
       The optional <code class="parameter">offset</code> parameter specifies
       the position from which the search should be performed.
       If the offset is negative, it is counted from the end of the string.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">encoding</code></dt>

     <dd>

      <p class="para">
       If <code class="parameter">encoding</code> parameter is omitted or <strong><code>null</code></strong>,
       <code class="parameter">string</code> are assumed to be encoded in
       <a href="iconv.configuration.html" class="link">iconv.internal_encoding</a>.
      </p>
     </dd>

    
   </dl>

  </p>
  <p class="para">
   If <code class="parameter">haystack</code> or <code class="parameter">needle</code> is
   not a string, it is converted to a string and applied as the ordinal
   value of a character.
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.iconv-strpos-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the numeric position of the first occurrence of
   <code class="parameter">needle</code> in <code class="parameter">haystack</code>.
  </p>
  <p class="para">
   If <code class="parameter">needle</code> is not found,
   <span class="function"><strong>iconv_strpos()</strong></span> will return <strong><code>false</code></strong>.
  </p>
  <div class="warning"><strong class="warning">警告</strong><p class="simpara">此函数可能返回布尔值
<strong><code>false</code></strong>，但也可能返回等同于 <strong><code>false</code></strong> 的非布尔值。请阅读 <a href="language.types.boolean.html" class="link">布尔类型</a>章节以获取更多信息。应使用
<a href="language.operators.comparison.html" class="link">===
运算符</a>来测试此函数的返回值。</p></div>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.iconv-strpos-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">encoding</code> is nullable now.
      </td>
     </tr>

     <tr>
      <td>7.1.0</td>
      <td>
       Support for negative <code class="parameter">offset</code>s has been added.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.iconv-strpos-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.strpos.html" class="function" rel="rdfs-seeAlso">strpos()</a> - 查找字符串首次出现的位置</span></li>
    <li class="member"><span class="function"><a href="function.iconv-strrpos.html" class="function" rel="rdfs-seeAlso">iconv_strrpos()</a> - Finds the last occurrence of a needle within a haystack</span></li>
    <li class="member"><span class="function"><a href="function.mb-strpos.html" class="function" rel="rdfs-seeAlso">mb_strpos()</a> - 查找字符串在另一个字符串中首次出现的位置</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>